www.gusucode.com > VC++ 实现多窗口多视图例子-源码程序 > VC++ 实现多窗口多视图例子-源码程序/code/FormSwap2/MySplit.cpp
//Download by http://www.NewXing.com //////////////////////////////////////////////////////////////// // 1998 Microsoft Systems Journal. // If this code works, it was written by Paul DiLascia. // If not, I don't know who wrote it. // Compiles with Visual C++ 5.0 on Windows 95 // // Implementation for splitter window with changeable view panes // #include "StdAfx.h" #include "MySplit.h" #include <afxpriv.h> #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ////////////////// // This function changes the view in a splitter window // void CMySplitterWnd::ChangeView(int row, int col, CRuntimeClass* pViewClass) { ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView))); CView* pView = STATIC_DOWNCAST(CView, GetPane(row, col)); CFrameWnd* pFrame = pView->GetParentFrame(); ASSERT(pFrame); // set up create context to preserve doc/frame etc. CCreateContext cc; memset(&cc, 0, sizeof(cc)); cc.m_pNewViewClass = pViewClass; cc.m_pCurrentDoc = pView->GetDocument(); cc.m_pNewDocTemplate = cc.m_pCurrentDoc ? cc.m_pCurrentDoc->GetDocTemplate() : NULL; cc.m_pCurrentFrame = pFrame; DeleteView(row, col); // delete old view VERIFY(CreateView(row, col, // create new one pViewClass, CSize(0,0), // will fix in RecalcLayout &cc)); RecalcLayout(); // recompute layout // initialize the view CWnd* pWnd = GetPane(row, col); if (pWnd) pWnd->SendMessage(WM_INITIALUPDATE); } ////////////////// // Splitter wnd function to route commands to all splitter panes/views. // This lets all panes, not just the active pane, handle messages. // BOOL CMySplitterWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { for (int row=0; row<GetRowCount(); row++) { for (int col=0; col<GetColumnCount(); col++) { if (GetPane(row,col)->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; } } // Call default routing--very important! return CSplitterWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }